Slides for the RStudio Tips and Tricks Series are available

https://jeremy-allen.github.io/rstudio-tps/





library(palmerpenguins)
library(tidyverse)
library(janitor)
library(here)

Before we dive in, two things

Set preview in viewer pane

viewer pane


Visual Editor will be our quick preview tool throughout this series

Visual Editor


Adjusting Global Options in the RStudio IDE

😄 Pro tip: cmd+, to access global options


Rearrange panels


Change theme


Show chunk output in console


Default R version & don’t save workspace data


Set repo for RStudio Public Package Manager

😄 Pro tip: If you are on a Linux server, see what operating system you are on by running this in your console: 


system("lsb_release -a")


Then go to RStudio Public Package Manager


Allow scroll past end of doc & rainbow parentheses


Command Palette is amazing!

😄 shift+cmd+p then do anything

Use shift+cmd+p to access the command palette and:

  • Toggle Memory Usage Display in Environment Pane
  • Syntax highlighting in console output
  • Knit Current Document
  • Highlight Selected Line


Adjust the code chunk options at the top of this file to hide code and re-knit


Expand the outline

😄 Pro tip: Navigate your document with the outline 

😄 also ctl+shift+o

 

 


Outline is also down here



Code folding

Go back up to the line “set repo for RStudio Public Package Manager”
😄 Click the little triangle next to the line number



Command History in the console

😄 Pro tip: in the console type a couple of letters then cmd+up for visual of matches

 


Open File in New Column

😄 Pro tip: open file in new column is great for Shiny apps when you have ui, sever, and css files



Comment and not

😄 Pro tip: highlight multiple lines of code, shift+ctl+c to comment all


Move line

😄 Pro tip: alt+up or alt+down to move lines


Multi-line

😄 Pro tip: ctl+alt+down or ctl+alt+up to have multi-line cursor
You try: add commas after starts_with() and mean

df %>% 
  summarise(
    across(
      starts_with("culmen")
      mean
      na.rm = TRUE
      )
    )


Which parentheses?

😄 Pro tip: double click one of the parentheses to highlight what it contains

div(
  class = "outer",
  div(
    class = "container",
    div(class = "data",
        df %>% 
          filter(
            str_detect(Species, "Chin"),
            Sex == "MALE",
            Island == "Dream"
          ) %>% 
          summarise(
            across(
              starts_with("culmen"),
              mean,
              na.rm = TRUE
            )
          )
    )
  )
)

<br

Execute long-running code in jobs

😄 Pro tip: execute code or scripts as jobs in separate R sessions so you can keep working in your IDE

Jobs

git in the IDE (a very short intro)

😄 Pro tip: ctl+alt+m to open the commit window
😄 Pro tip: can stage or discard chunks, even lines
😄 Pro tip: select first file then cmd+a to highlight all, then check one to check all

Git discard


more on git in RStudio